/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccessManager.ViaGrant;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.GuestAccount;
/*     */ import com.zimbra.cs.account.MailTarget;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import com.zimbra.soap.type.TargetBy;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CheckRight
/*     */   extends RightDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  48 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  50 */     Element eTarget = request.getElement("target");
/*  51 */     String targetType = eTarget.getAttribute("type");
/*  52 */     TargetBy targetBy = null;
/*  53 */     String target = null;
/*  54 */     if (TargetType.fromCode(targetType).needsTargetIdentity()) {
/*  55 */       targetBy = TargetBy.fromString(eTarget.getAttribute("by"));
/*  56 */       target = eTarget.getText();
/*     */     }
/*     */     
/*  59 */     Element eGrantee = request.getElement("grantee");
/*  60 */     GranteeType granteeType = GranteeType.fromCode(eGrantee.getAttribute("type", GranteeType.GT_EMAIL.getCode()));
/*     */     
/*  62 */     if ((granteeType != GranteeType.GT_USER) && (granteeType != GranteeType.GT_EMAIL)) {
/*  63 */       throw ServiceException.INVALID_REQUEST("invalid grantee type " + granteeType, null);
/*     */     }
/*  65 */     GranteeSelector.GranteeBy granteeBy = GranteeSelector.GranteeBy.fromString(eGrantee.getAttribute("by"));
/*  66 */     String granteeVal = eGrantee.getText();
/*     */     
/*  68 */     Element eRight = request.getElement("right");
/*  69 */     String right = eRight.getText();
/*     */     
/*  71 */     Element eAttrs = request.getOptionalElement("attrs");
/*  72 */     Map<String, Object> attrs = eAttrs == null ? null : AdminService.getAttrs(request);
/*     */     
/*  74 */     MailTarget grantee = null;
/*  75 */     NamedEntry ne = GranteeType.lookupGrantee(Provisioning.getInstance(), granteeType, granteeBy, granteeVal);
/*  76 */     if ((ne instanceof MailTarget)) {
/*  77 */       grantee = (MailTarget)ne;
/*     */     } else {
/*  79 */       grantee = new GuestAccount(granteeVal, null);
/*     */     }
/*     */     
/*  82 */     if (!granteeVal.equals(zsc.getAuthtokenAccountId()))
/*     */     {
/*     */ 
/*  85 */       checkCheckRightRight(zsc, (grantee instanceof Account) ? GranteeType.GT_USER : GranteeType.GT_GROUP, granteeBy, granteeVal, true);
/*     */     }
/*     */     
/*  88 */     AccessManager.ViaGrant via = new AccessManager.ViaGrant();
/*  89 */     boolean result = RightCommand.checkRight(Provisioning.getInstance(), targetType, targetBy, target, grantee, right, attrs, via);
/*     */     
/*     */ 
/*  92 */     Element resp = zsc.createElement(AdminConstants.CHECK_RIGHT_RESPONSE);
/*     */     
/*  94 */     resp.addAttribute("allow", result);
/*  95 */     if (via.available()) {
/*  96 */       Element eVia = resp.addElement("via");
/*     */       
/*  98 */       Element eViaTarget = eVia.addElement("target");
/*  99 */       eViaTarget.addAttribute("type", via.getTargetType());
/* 100 */       eViaTarget.setText(via.getTargetName());
/*     */       
/* 102 */       Element eViaGrantee = eVia.addElement("grantee");
/* 103 */       eViaGrantee.addAttribute("type", via.getGranteeType());
/* 104 */       eViaGrantee.setText(via.getGranteeName());
/*     */       
/* 106 */       Element eViaRight = eVia.addElement("right");
/* 107 */       eViaRight.addAttribute("deny", via.isNegativeGrant());
/* 108 */       eViaRight.setText(via.getRight());
/*     */     }
/*     */     
/* 111 */     return resp;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 116 */     relatedRights.add(Rights.Admin.R_checkRightUsr);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CheckRight.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */